Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: retrigger check-run using v3 server endpoint #369

Merged
merged 10 commits into from
Jan 27, 2025

Conversation

teodorus-nathaniel
Copy link
Contributor

@teodorus-nathaniel teodorus-nathaniel commented Jan 27, 2025

resolves https://github.com/holdex/pr-time-tracker-webhooks/issues/454

Summary by CodeRabbit

  • Configuration Changes

    • Disabled several background jobs by default
    • Added concurrency limit for specific job
  • API Improvements

    • Enhanced check run triggering mechanism
    • Improved error handling for server requests

Copy link

vercel bot commented Jan 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
autoinvoice ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 27, 2025 8:02am

Copy link

coderabbitai bot commented Jan 27, 2025

Walkthrough

The pull request introduces modifications to job definitions in the Trigger.dev configuration and the submissions API server route. The changes primarily involve disabling specific jobs by setting their enabled property to false, including custom-event-streaming, discord-send-message, and github-create-bug-report-issue. Additionally, a new function triggerRequestCheckRun is added to the submissions API route to handle check run triggering with improved error handling and axios-based request mechanism.

Changes

File Change Summary
src/lib/server/trigger-dev/jobs/index.ts - Set enabled: false for multiple job definitions
- Added concurrencyLimit: 1 to check_run_streaming job
src/routes/api/submissions/+server.ts - Imported axios and environment variables
- Replaced checkRunFromEvent with triggerRequestCheckRun
- Added new async function for triggering check runs

Assessment against linked issues

Objective Addressed Explanation
Disable custom event
Rerun check run on submission

Possibly related PRs

Suggested reviewers

  • georgeciubotaru
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@teodorus-nathaniel
Copy link
Contributor Author

@teodorus-nathaniel
Copy link
Contributor Author

@georgeciubotaru please let me know if there is any more place where it triggers custom-event job.
from what I found, its only this one

@teodorus-nathaniel teodorus-nathaniel marked this pull request as ready for review January 27, 2025 08:03
@teodorus-nathaniel
Copy link
Contributor Author

after this gets merged, I'll remove all existing webhooks to the prod cloud v2 server,
while it won't make any differences because we have disabled all the jobs, but I just want to clean them up.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/routes/api/submissions/+server.ts (1)

170-193: Consider enhancing error handling and request reliability.

While the implementation is functional, consider these improvements:

  1. Add specific error handling for different failure scenarios (network issues, authentication errors, etc.)
  2. Specify a timeout for the axios request
  3. Implement a retry mechanism for transient failures

Here's a suggested implementation:

 async function triggerRequestCheckRun(data: {
   org: string;
   repoName: string;
   senderId: number;
   senderLogin: string;
   prNumber: number;
 }) {
   try {
     const url = TRIGGER_SERVER_URL;
     const secret = TRIGGER_SERVER_SECRET;

     if (!url || !secret) throw new Error('Trigger server not configured');

     const res = await axios.post(`${url}/api/submission-event`, data, {
       headers: {
         'x-trigger-server-secret': secret
-      }
+      },
+      timeout: 5000, // 5 second timeout
+      validateStatus: status => status === 200 // Only 200 is considered success
     });

-    if (res.status !== 200) throw new Error(res.data.message);
   } catch (e) {
-    throw new Error((e as any)?.response?.data || 'Failed to trigger check run');
+    if (axios.isAxiosError(e)) {
+      if (e.code === 'ECONNABORTED') {
+        throw new Error('Request timed out');
+      }
+      if (e.response) {
+        throw new Error(`Server error: ${e.response.data?.message || e.response.statusText}`);
+      }
+      if (e.request) {
+        throw new Error('No response received from server');
+      }
+    }
+    throw new Error('Failed to trigger check run: ' + e.message);
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a70c7a and bce6c69.

📒 Files selected for processing (2)
  • src/lib/server/trigger-dev/jobs/index.ts (3 hunks)
  • src/routes/api/submissions/+server.ts (4 hunks)
🔇 Additional comments (5)
src/routes/api/submissions/+server.ts (2)

2-2: LGTM! Necessary imports added.

The addition of axios and environment variables from private env is appropriate for the new functionality.

Also applies to: 5-5


66-72: LGTM! Consistent parameter passing in both handlers.

The replacement of checkRunFromEvent with triggerRequestCheckRun is implemented consistently in both POST and PATCH handlers, with appropriate parameter mapping from their respective contexts.

Also applies to: 142-148

src/lib/server/trigger-dev/jobs/index.ts (3)

144-144: LGTM! Disabled non-essential jobs.

Disabling discord-send-message and github-create-bug-report-issue jobs is appropriate as they are not critical for the check-run functionality.

Also applies to: 166-166


111-111: LGTM! Appropriate concurrency limit.

Setting concurrencyLimit to 1 for check-run related jobs is appropriate to prevent potential race conditions when handling check runs.


110-110: Verify impact of disabling custom-event-streaming job.

The job is being disabled, but based on the PR objectives and comments, this is the only instance where the custom-event job is triggered. Please confirm if this is intentional.

Run this script to verify usage:

✅ Verification successful

Disabling custom-event-streaming job appears intentional and safe

The custom events are used for auxiliary monitoring and don't affect core GitHub integration functionality. All critical event handlers (issues, PRs, reviews, check runs) remain enabled.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for custom event triggers in the codebase
echo "Searching for custom event triggers..."
rg -l "custom_event" --type ts --type js

echo "Searching for sendEvent calls..."
rg -l "sendEvent.*custom.*event" --type ts --type js

Length of output: 334


Script:

#!/bin/bash
# Check content of files and broader event patterns
echo "Content of utils.ts:"
rg -A 5 -B 5 "custom_event" src/lib/server/trigger-dev/utils.ts

echo -e "\nContent of jobs/index.ts:"
rg -A 5 -B 5 "custom_event" src/lib/server/trigger-dev/jobs/index.ts

echo -e "\nBroader search for event handling:"
rg "event" src/lib/server/trigger-dev/utils.ts src/lib/server/trigger-dev/jobs/index.ts

Length of output: 2759

@georgeciubotaru
Copy link
Contributor

@teodorus-nathaniel merge the PR after clarifiying with the previous one https://github.com/holdex/pr-time-tracker-webhooks/pull/455

@teodorus-nathaniel
Copy link
Contributor Author

@georgeciubotaru action done in previous pr, Ill merge this

@teodorus-nathaniel teodorus-nathaniel merged commit 0bfd412 into main Jan 27, 2025
5 checks passed
@teodorus-nathaniel teodorus-nathaniel deleted the chore/disable-all-jobs branch January 27, 2025 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants